/*
 * HttpMobileConnector.java
 *
 * Created on 26 de Maio de 2007, 14:02
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.connection;

import com.sun.midp.io.Properties;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.microedition.io.HttpConnection;

/**
 *
 * @author $Leandro$
 */
public abstract class HttpMobileConnector implements Runnable {       
    // dados de entrada..
    public InputStream input;
               
    public HttpConnection http;
    
    protected String url = null;
    
    protected Hashtable parameters;

    public boolean isFinished;
    
    public abstract void connect();
    
    public void run(){
        isFinished = false;
        connect();
    }
           
    public String mountData(String url,Hashtable map){
        this.url = url;
        
        StringBuffer result = new StringBuffer();
        
        Enumeration elems = map.elements();
        Enumeration keys = map.keys();
        
        while(elems.hasMoreElements()){
            String item = (String) elems.nextElement();
            String itemKey = (String) keys.nextElement();
            
            result.append(itemKey + "=");
            result.append(item);
            
            if(elems.hasMoreElements()){
                result.append("&");
            }
        }        
        return encodeData(result.toString());
    }
    
    public abstract String encodeData(String result);        
}
